<template>
	<view class="">
		<view class="childrenBox">
			<view class="childrenOptionsBox">
				<view class="childrenOptionsTitle">姓名</view>
				<view class="childrenOptionsDes">{{helpUser.applicantName?helpUser.applicantName:'暂无'}}</view>
			</view>
			<view class="childrenOptionsBox">
				<view class="childrenOptionsTitle">地址</view>
				<view class="childrenOptionsDes">{{address?address:'暂无'}}</view>
			</view>
			<view class="childrenOptionsBox">
				<view class="childrenOptionsTitle">电话</view>
				<view class="childrenOptionsDes">{{helpUser.contactNumber?helpUser.contactNumber:'暂无'}}</view>
			</view>
		</view>
		<view class="line1">
			
		</view>
		<view class="button" v-if="textStatus==0" @click="link(isSave == 0?'/pages/kancha/index':'/pages/kancha/familyInfo')">
			现场调查
		</view>
		<view class="button" v-if="photoStatus==0" @click="link('/pages/kancha/photo')">
			现场拍照
		</view>
		<!-- <view class="button" @click="changeStatus(1)">
			无人在家
		</view> -->
		<view class="button" v-if="executionStatus !=2" @click="changeStatus(3)">
			拨打电话未接通
		</view>
		<view class="zhenchayuan">侦查员——{{user.nickName?user.nickName:user.userName}}</view>
		<!-- <view class="mask" v-if="showMask" @click.stop="maskClick">
			
		</view> -->
	</view>
</template>

<script>
	import province from '@/address/sheng.js'
	import city from '@/address/shi.js'
	import county from '@/address/qu.js'
	let sheng = {},shi={},qu={};
	province.forEach((item)=>{
		sheng[item.code+'0000'] = item.name
	})
	city.forEach((item)=>{
		shi[item.code+'00'] = item.name
	})
	county.forEach((item)=>{
		qu[item.code] = item.name
	})
	export default {
		data(){
			return {
				user:{},
				sheng,shi,qu,
				helpUser:{},
				address:'',
				photoStatus:0,
				textStatus:0,
				isSave:0,
				executionStatus:2,
				errorMessage:'',
				showMask:true
			}
		},
		onShow() {
			this.helpUser = uni.getStorageSync('helpUser')
			this.user = uni.getStorageSync('user')
			this.isSave = uni.getStorageSync('isSave')
			this.photoStatus = uni.getStorageSync('photoStatus')
			this.textStatus = uni.getStorageSync('textStatus')
			this.address = this.userInfoGetAddress()
			this.getTaskDetail()
			// this.getPostion()
		},
		methods:{
			
			// 获取位置信息
			getPostion(){
				let that = this
				uni.showLoading({
					title:'请稍等...'
				})
				uni.getLocation({
				    type: 'wgs84',
				    success: async function (res) {
				        console.log('当前位置的经度：' + res.longitude);
				        console.log('当前位置的纬度：' + res.latitude);
						let data = await that.$post('/app/bus/rangeLimit',{
							id:uni.getStorageSync('taskId'),
							lng:res.longitude,
							lat:res.latitude
						})
						if(data.code == 200){
							that.showMask = false
						}
						if(data.code == -1){
							that.errorMessage = data.msg
						}
						if(data.code == 500){
							that.errorMessage = '获取定位信息失败，请重新进入'
						}
						uni.hideLoading()
				    },
					fail:function(e){
						that.errorMessage = '获取定位信息失败，请重新进入'
						uni.hideLoading()
						uni.showModal({
							content: '获取定位信息失败，是否检查配置',
							showCancel: true,
							cancelText: '取消',
							confirmText: '确定',
							success: res => {
								if(res.confirm){
									uni.openSetting({
									  success(res) {
									    console.log(res.authSetting)
									  }
									});
								}
							},
							fail: () => {},
							complete: () => {}
						});
					}
				});
			},
			// 蒙版点击事件
			maskClick(){
				uni.showModal({
					content: this.errorMessage,
					showCancel: false,
					confirmText: '确认'
				});
			},
			// 获取分组
			async getTaskDetail(){
				uni.showLoading({
					title:'请稍等...'
				})
				let res = await this.$get('/app/bus/taskMainById?id='+uni.getStorageSync('taskId'),{})
				console.log(res)
				if(res.code == 200){
					this.executionStatus = res.data.executionStatus;
					uni.setStorageSync('executionStatus',this.executionStatus)
				}
				uni.hideLoading()
			},
			userInfoGetAddress(){
				let residenceAddressCounty = this.helpUser.residenceAddressCounty?this.helpUser.residenceAddressCounty:''
				let residenceAddressStreet = this.helpUser.residenceAddressStreet?this.helpUser.residenceAddressStreet:''
				let residenceAddressCommunity = this.helpUser.residenceAddressCommunity?this.helpUser.residenceAddressCommunity:''
				return residenceAddressCounty+residenceAddressStreet+residenceAddressCommunity
				// if(code){
				// 	return this.sheng[(code+'').slice(0,2)+'0000']+' '+this.shi[(code+'').slice(0,4)+'00']+' '+this.qu[code+''] + this.helpUser.residentialAddressStreet
				// } else {
				// 	return this.helpUser.residentialAddressStreet?this.helpUser.residentialAddressStreet:''
				// }
			},
			link(url){
				this.changeButtonStatus()
				uni.redirectTo({
					url
				})
			},
			async changeButtonStatus(){
				let changeStatus = await this.$get('/app/bus/taskStatus?id='+uni.getStorageSync('taskId')+'&taskStatus=2')
			},
			async changeStatus1(status){
				uni.showLoading({
					title:'请稍等...'
				})
				let data = {
					id:uni.getStorageSync('taskId'),
					taskStatus:status
				}
				let res = await this.$get('/app/bus/taskStatus',data)
				if(res.code == 200){
					uni.showModal({
						content:'状态已确认，是否返回首页？',
						showCancel: true,
						cancelText: '取消',
						confirmText: '确认',
						success: res => {
							if(res.confirm){
								uni.navigateBack({
									
								})
							}
						}
					});
				} else {
					uni.showToast({
						title: '更新状态失败',
						icon:'none',
						duration:2000
					});
				}
				uni.hideLoading()
			},
			changeStatus(status){
				uni.showModal({
					content: '是否确认？',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						if(res.confirm){
							this.changeStatus1(status)
						}
					}
				});
			}
		}
	}
</script>

<style scoped>
	.childrenBox{
		width: 600rpx;
		margin: 0 auto;
		position: relative;
		transition: all 0.3s;
		overflow: hidden;
	}
	.childrenOptionsBox{
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		padding: 20rpx 0;
	}
	.childrenOptionsTitle{
		font-size: 26rpx;
		line-height: 30rpx;
		color: #ccc;
	}
	.childrenOptionsDes{
		font-size: 26rpx;
		line-height: 30rpx;
		width: 450rpx;
		text-align: right;
	}
	.rightOpen{
		transform: rotate(90deg);
	}
	.line1{
		height: 20rpx;
		background-color: #efefef;
	}
	.zhenchayuan{
		font-size: 24rpx;
		color:#ccc;
		margin-top: 20rpx;
		text-align: center;
	}
	.button{
		width: 690rpx;
		line-height: 90rpx;
		margin: 0 auto;
		margin-top: 40rpx;
		background-color: #fa5444;
		text-align: center;
		color: white;
	}
	.mask{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
	}
</style>
